\documentclass[review,3p,times]{elsarticle}

%To remove the line "Preprint submitted to elsevier"
\makeatletter
\def\ps@pprintTitle{%
   \let\@oddhead\@empty
   \let\@evenhead\@empty
   \def\@oddfoot{\reset@font\hfil\thepage\hfil}
   \let\@evenfoot\@oddfoot
}
\makeatother

%\usepackage{lineno,hyperref}
%\modulolinenumbers[5]

%to write indented java code
\usepackage{listings}
\usepackage{color}

\definecolor{dkgreen}{rgb}{0,0.6,0}
\definecolor{gray}{rgb}{0.5,0.5,0.5}
\definecolor{mauve}{rgb}{0.58,0,0.82}

\lstset{frame=tb,
  language=Java,
  aboveskip=3mm,
  belowskip=3mm,
  showstringspaces=false,
  columns=flexible,
  basicstyle={\small\ttfamily},
  numbers=none,
  numberstyle=\tiny\color{gray},
  keywordstyle=\color{blue},
  commentstyle=\color{dkgreen},
  stringstyle=\color{mauve},
  breaklines=true,
  breakatwhitespace=true,
  tabsize=3
}

\newcounter{programcounter}
\usepackage{verbatim}
\usepackage{hyperref}
\usepackage{algorithm}
\usepackage[noend]{algpseudocode}
\graphicspath{{./figures/}}
\usepackage{array}
\usepackage{amsmath}
\usepackage{amsthm}
\newtheorem{lemm}{Lemma}
\newtheorem{slemm}{Sublemma}[lemm]
\newtheorem{obser}{Observation}
\usepackage{booktabs}
\usepackage{subfig}
\usepackage{pifont}
\usepackage{mathtools}
\DeclarePairedDelimiter\ceil{\lceil}{\rceil}
\DeclarePairedDelimiter\floor{\lfloor}{\rfloor}
\algnewcommand\algorithmicforeach{\textbf{for each}}
\algdef{S}[FOR]{ForEach}[1]{\algorithmicforeach\ #1\ \algorithmicdo}
\algdef{SE}{WHILE}{ENDWHILE}[1]{\textbf{do} \(\mbox{#1}\) \textbf{while}}{\textbf{end while}}
\usepackage[utf8]{inputenc}
\begin{document}
\begin{frontmatter}
\title{\textbf{Co}nnected \textbf{Ve}hicle \textbf{T}raffic control algorithm \textbf{T}esting Soft\textbf{ware} (\textbf{CoVeTTware}) using VISSIM tool, BSM and SPAT messages}
\author{Neeta A Eapen, $\space$ Robert B Heckendorn}
%\address{University of Idaho, USA}
\end{frontmatter}
\begin{figure}
    \centering
    \includegraphics[width=0.3\textwidth]{figures/UI_logo_horizontal.png}
\end{figure}


%\linenumbers
\section{Grant Information}
This work is supported by PACTRANS under grant EN1828.

\section{Statement of Purpose}
This project aims to design and develop \textbf{Co}nnected \textbf{Ve}hicle \textbf{T}raffic control algorithm \textbf{T}esting Soft\textbf{ware}  (\textbf{CoVeTTware}). The traffic simulation in this work is done using the VISSIM simulation tool. The COM interface is used to access the objects of the VISSIM simulation tool. The exchange of information between VISSIM and CoVeTTware is performed in real-time. CoVeTTware retrieves the information of vehicles at intersections from VISSIM and generates the Basic Safety Messages (BSMs) of the vehicles in real-time, according to the  SAE J2735 standard. The BSMs can be used by a connected vehicle traffic control algorithm to generate the signal information for the intersections. The signal information includes the signal phase to be set for a signal and the time for which the signal phase should be set. The signal information is used by CoVeTTware to generate the Signal Phasing and Timing (SPAT) messages, according to the  SAE J2735 standard. The signal status of the signals of the intersections in VISSIM is changed in real-time based on the SPAT messages, using CoVeTTware. When the time of the given phase of the signal expires, CoVeTTware resets the signal phase as \textit{UNDEFINED}. This model can be used to test any connected vehicle traffic control algorithm. Figure \ref{fig:blockDiagram} shows the exchange of data between CoVeTTware, VISSIM, and the traffic control algorithm. 

\begin{figure}[h!]
    \centering
    \includegraphics[scale=.4]{figures/covettware.png}
    \caption{Data exchange between CoVeTTware, VISSIM,and the traffic control algorithm}
    \label{fig:blockDiagram}
\end{figure}


\section{Overview}
This document explains how the Basic Safety Message (BSM) of vehicles can be retrieved from VISSIM using CoVeTTware. It also explains how signal information is used to control the signal status of intersections in VISSIM, using CoVeTTware.  We assume that there exists a signal controller for each intersection in the VISSIM input file. The intersection ID$/$number and the intersection name  corresponds to the signal controller number and the signal controller name, respectively. Section \ref{preliminaries} explains the preliminary steps to be done. Section \ref{objectCreation} explains the object to be created to use CoVeTTware. Section \ref{finalStep} explains the function to be invoked at the end of all operations using CoVeTTware. Section \ref{simuFunctions} explains the functions which help in the simulation of the network. Section \ref{BSMmain} explains the BSM fields and the functions used to generate, display, and write BSM messages of the vehicles in the VISSIM network. Section \ref{SPATmain} explains the SPAT fields, and the functions used to generate, display, and write SPAT messages of intersections in the VISSIM network.  Section \ref{messageGeneration} explains the steps to be followed to test any connected vehicle traffic control algorithm.

\setcounter{programcounter}{1}

\section{Preliminaries} \label{preliminaries}
In order to access VISSIM from Java code, \href{https://sourceforge.net/projects/jacob-project/}{Java COM bridge (Jacob)} is needed. The following steps need to be done. 
\begin{itemize}
    \item Register COM server in VISSIM. See Figure \ref{fig:register}.
    \item Add \textit{jacob*.dll} to \textit{c:$\setminus$windows$\setminus$system32}
    \item Add \textit{jacob.jar} to the library of your project
\end{itemize}

\begin{figure}[h!]
    \centering
    \includegraphics[scale=.5]{figures/register.png}
    \caption{Register COM server}
    \label{fig:register}
\end{figure}

% Location in my one drive: C:\Users\eape2084\OneDrive - University of Idaho\from 17 August 2021\traffic project\traffic project with BSM and SPAT\covettwareProject.jar

To use CoVeTTware, add  \href{https://vandalsuidaho-my.sharepoint.com/:u:/g/personal/eape2084_vandals_uidaho_edu/EX-URQ37Ib5Pl2nKIeFE2kkBqxqowo2ug6dyKC3AtD4PxA?e=WJR3UW}{covettwareProject.jar}  to the library of your project.

\section{Object creation for using CoVeTTware} \label{objectCreation}
To use CoVeTTware, create an object of \textit{covettware}. The VISSIM input gets loaded in this process. The files for writing BSM and SPAT messages are also created here. If file is already present, it will be overwritten. \newline \newline
public covettware(String VissimFilePath, String bsmFilePath, String spatFilePath) \newline
Parameters: String VissimFilePath - The path to VISSIM input file (*.inpx), String bsmFilePath - The path to the file where BSM messages are to be written (*.txt), String spatFilePath - The path to the file where SPAT messages are to be written (*.txt). \newline
The syntax for object creation of \textit{covettware} is as follows:
\begin{lstlisting}
covettware obj = new covettware(VissimFilePath, bsmFilePath, spatFilePath); 
\end{lstlisting}

\section{Function for safe closing} \label{finalStep}
The function finalStep() should be used at the end of the program. It terminates VISSIM and the files (for writing the BSM and SPAT messages) safely. \newline \newline
public void finalStep() \newline
Parameters : No parameters \newline
Return type : void \newline
The syntax for finalStep() is as follows:
\begin{lstlisting}
obj.finalStep();
\end{lstlisting}

\section{Functions related to simulation} \label{simuFunctions}
This section explains the functions which help in the simulation of the network.

\subsection{public void runVissimOnce()}
This function is used to run the simulation of VISSIM by one step. \newline
Parameters: No parameters \newline
Return type : void \newline
The syntax for this function is as follows:
\begin{lstlisting}
obj.runVissimOnce();
\end{lstlisting}

\subsection{public int numberOfRunsFromSecs(double t)}
Finds the maximum number of times the function "runVissimOnce" should be invoked to run VISSIM for a specified time in the simulation. \newline
Parameters : double t - Simulation time \newline
Return type : int - Returns the number of times the function "runVissimOnce" should be invoked. \newline
The syntax for this function is as follows:
\begin{lstlisting}
int n = obj.numberOfRunsFromSecs(t); 
\end{lstlisting}


\section{Basic Safety Message (BSM)} \label{BSMmain}
Basic Safety Message (BSM) is a message which gives information about a vehicle in the VISSIM simulation. For each vehicle, ten BSM messages are generated per second.
Section \ref{bsmFields} explains the fields of basic safety message. Section \ref{BSMfunctions} explains the functions or methods for BSM.

%Section \ref{bsmGeneration} explains the steps to be done to generate the basic safety messages of vehicles in a VISSIM simulation.

\subsection{BSM fields}\label{bsmFields}
 The North, South, East, and West directions are along positive y-axis, negative y-axis, positive x-axis, and negative x-axis, respectively. The unit is metric or imperial, depending on the selection in the VISSIM input file.
The fields of BSM are explained in Table \ref{table:1}. The java class for BSM is :
\begin{lstlisting}
public class BSM
{
    int vehicleID;
    int messageCount;
    float currentTime;
    float latitude;
    float longitute;
    float elevation;
    float speed; 
    float heading;
    float yawRate;
    float acceleration;
    float lateralAccelaration=0; /* unused field*/
    float verticalAcceleration=0; /* unused field*/
    int brakeOnWheels;
    int controlSystems=0; /* unused field*/
    float vehicleLength;
    float vehicleWidth;
}
\end{lstlisting}

\begin{table}[h!]
\centering
\begin{tabular}{p{0.15\linewidth}p{0.06\linewidth}p{0.58\linewidth}p{0.1\linewidth}p{0.1\linewidth}} \hline
Field & Type & Description  & Metric & Imperial\\ 
 & & & Unit & Unit\\
\hline
vehicleID & Integer & To identify the vehicle & - & -\\
messageCount & Integer & The number of BSMs sent from the vehicle & - & - \\
currentTime & float & The time of BSM generation in the simulation & seconds & seconds \\
latitude & float & Distance of the vehicle North or South of x-axis & meters & feet\\
 &  & (Value is positive towards North and negative towards South) & & \\
longitude & float & Distance of the vehicle East or West of y-axis  & meters & feet\\
&  & (Value is positive towards East and negative towards West) & & \\
elevation & float & Height of the vehicle above the surface & meters & feet\\
 &  & ($=$ Sum of heights of the road and the vehicle) & &  \\
speed & float & Speed of the vehicle &  km / h &  mph \\
acceleration & float & Acceleration of the vehicle & m / s$^{2}$ & ft / s$^{2}$\\
heading & float & The angle of deviation of the vehicle from North direction & degrees & degrees \\
&  & (Value is positive in the anti-clockwise direction from North  and negative in the clockwise direction from North) & & \\
yawRate & float & The rate of change of heading & degrees / s & degrees / s \\
brakeOnWheels & Integer & Set as 1 if brake is applied on wheels, and 0 otherwise & - & -\\
vehicleLength & float & The length of the vehicle & meters & feet \\
vehicleWidth & float & The width of the vehicles & meters & feet \\
[1ex] 
 \hline
\end{tabular}
\caption{BSM fields}
\label{table:1}
\end{table}


    
\subsection{Functions for BSM}\label{BSMfunctions}

\subsubsection{public List$<$BSM$>$ getBSMForAllVehiclesForAllIntersections()}
Fetches the BSM messages of all vehicles in the network. \newline
Parameters: No parameters \newline
Return type: List$<$BSM$>$ - Returns the list of BSM messages of all vehicles in the network.

\subsubsection{public List$<$BSM$>$ getBSMforIntersection(String signalControllerName, double distance)}
Fetches the BSM messages  within a specified distance from the signal heads of an intersection. BSM messages of all vehicles approaching the intersection, which are within the specified distance, are fetched. \newline
Parameters: String signalControllerName - Name of the intersection (signal controller), double distance - distance from signal heads of the intersection \newline
Return type: List$<$BSM$>$ - Returns the list of BSM messages which are fetched

\subsubsection{public List$<$BSM$>$ getBSMforIntersection(int intersectionNumber, double distance)}
Fetches the BSM messages  within a specified distance from the signal heads of an intersection. BSM messages of all vehicles approaching the intersection, which are within the specified distance, are fetched. \newline
Parameters: int intersectionNumber - Identification number of the intersection (signal controller), double distance - distance from signal heads of the intersection \newline
Return type: List$<$BSM$>$ - Returns the list of BSM messages which are fetched

\subsubsection{public List$<$BSM$>$ getBSMforSignalHead(String signalHeadName, double distance)}
Fetches the BSM messages  within a specified distance from a signal head of an intersection. BSM messages of all vehicles approaching the signal head, which are within the specified distance, are fetched. \newline
Parameters: String signalHeadName - Name of the signal head, double distance - distance from the signal head \newline
Return type: List$<$BSM$>$ - Returns the list of BSM messages which are fetched

\subsubsection{public List$<$BSM$>$ getBSMforSignalHead(int signalHeadNumber, double distance)}
Fetches the BSM messages  within a specified distance from a signal head of an intersection. BSM messages of all vehicles approaching the signal head, which are within the specified distance, are fetched. \newline
Parameters: int signalHeadNumber - Identification number of the signal head, double distance - distance from the signal head \newline
Return type: List$<$BSM$>$ - Returns the list of BSM messages which are fetched

\subsubsection{public void displayBSM(BSM b)}
Displays a BSM message of a vehicle. \newline
Parameters: BSM b - b contains a BSM message \newline
Return type: void

\subsubsection{public void displayListOfBSM(List$<$BSM$>$ listOfBSM)}
Displays a list of BSM messages of vehicles. \newline
Parameters: List$<$ BSM $>$ listOfBSM - listOfBSM contains a list of BSM messages \newline
Return type: void

\subsubsection{public void writeListOfBSMtoFile(List$<$BSM$>$ listOfBSM)}
Writes a list of BSM messages to  the text file specified during object creation of \textit{covettware}. The files of BSM are written, separated by \textit{,} as follows:\newline
\textit{vehicleID, messageCount, currentTime, latitude, longitude, elevation, heading, yawrate, speed, Acceleration, brakeOnWheels(1=yes,0=no), vehicleLength, vehicleWidth} \newline
Parameters:  List$<$ BSM $>$ listOfBSM - listOfBSM contains a list of BSM messages \newline
Return type : void

\subsection{Examples} \label{BSMexamples}
\subsubsection{Display a BSM message}
Display the fields of the BSM b.

\textbf{Program \theprogramcounter{}}
\begin{lstlisting}
obj.displayBSM(b);
\end{lstlisting}
\stepcounter{programcounter}
Sample output: \newline
vehicleID:20 \newline
messageCount:126 \newline
currentTime:9.5 \newline
latitude:2901.0 \newline
longitute:2750.0 \newline
elevation:4004.84 \newline
heading:0.0 \newline
yawRate:0.0 \newline
speed:33.489956 \newline
acceleration:0.58767843 \newline
brakeOnWheels:0 \newline
vehicleLength:13.815617 \newline
vehicleWidth:6.573727


\subsubsection{Report movement in the network}
Report the BSMs of all the vehicles in the network for 500 seconds in simulation. Also, write the BSMs to file.

\textbf{Program \theprogramcounter{}}
\begin{lstlisting}
int n = obj.numberOfRunsFromSecs(500); /*calculate the number of times runVissimOnce() function should be invoked to run the network for 500 seconds*/
for(int i=0; i<n; i++)
{
    obj.runVissimOnce();
    List<BSM> listOfBSM = obj.getBSMForAllVehiclesForAllIntersections(); /* listOfBSM contains the list of BSMs of all vehicles in network*/
    obj.displayListOfBSM(listOfBSM); /* displays the BSMs in listOfBSM */ 
    obj.writeListOfBSMtoFile(listOfBSM); /* writes the BSMs in listOfBSM to file */
}
\end{lstlisting}
\stepcounter{programcounter}



\subsubsection{Report movement of an intersection in the network, when intersection number is given}
Assume metric unit is used. Report the BSMs of all the vehicles within a distance of 100 meters for intersection 1, for 500 seconds in simulation.  Also, write the BSMs to file. 

\textbf{Program \theprogramcounter{}}
\begin{lstlisting}
int n = obj.numberOfRunsFromSecs(500); /*calculate the number of times runVissimOnce() function should be invoked to run the network for 500 seconds*/
for(int i=0; i<n; i++)
{
    obj.runVissimOnce(); 
    List<BSM> listOfBSM = obj.getBSMforIntersection(1,100); /* listOfBSM contains the list of BSMs of the vehicles of intersection 1 within 100 meters*/
    obj.displayListOfBSM(listOfBSM); /* displays the BSMs in listOfBSM */
    obj.writeListOfBSMtoFile(listOfBSM); /* writes the BSMs in listOfBSM to file */
}
\end{lstlisting}
\stepcounter{programcounter}

\subsubsection{Report movement of an intersection in the network, when intersection name is given}
Assume metric unit is used. Report the BSMs of all the vehicles within a distance of 100 meters for intersection "I1", for 500 seconds in simulation.  Also, write the BSMs to file. 

\textbf{Program \theprogramcounter{}}
\begin{lstlisting}
int n = obj.numberOfRunsFromSecs(500); /*calculate the number of times runVissimOnce() function should be invoked to run the network for 500 seconds*/
for(int i=0; i<n; i++)
{
    obj.runVissimOnce(); 
    List<BSM> listOfBSM = obj.getBSMforIntersection("I1",100); /* listOfBSM contains the list of BSMs of the vehicles of intersection I1 within 100 meters*/
    obj.displayListOfBSM(listOfBSM); /* displays the BSMs in listOfBSM */
    obj.writeListOfBSMtoFile(listOfBSM); /* writes the BSMs in listOfBSM to file */
}
\end{lstlisting}
\stepcounter{programcounter}

\subsubsection{Report movement of the signal head of an intersection in the network, when the signal head number is given}
Assume metric unit is used. Report the BSMs of all the vehicles within a distance of 100 meters from signal head 1, for 500 seconds in simulation.  Also, write the BSMs to file. 

\textbf{Program \theprogramcounter{}}
\begin{lstlisting}
int n = obj.numberOfRunsFromSecs(500); /*calculate the number of times runVissimOnce() function should be invoked to run the network for 500 seconds*/
for(int i=0; i<n; i++)
{
    obj.runVissimOnce(); 
    List<BSM> listOfBSM = obj.getBSMforSignalHead(1,100); /* listOfBSM contains the list of BSMs of the vehicles of signal head 1 within 100 meters*/
    obj.displayListOfBSM(listOfBSM); /* displays the BSMs in listOfBSM */
    obj.writeListOfBSMtoFile(listOfBSM); /* writes the BSMs in listOfBSM to file */
}
\end{lstlisting}
\stepcounter{programcounter}

\subsubsection{Report movement of the signal head of an intersection in the network, when the signal head name is given}
Assume metric unit is used. Report the BSMs of all the vehicles within a distance of 100 meters from the signal head "SH1" for 500 seconds in simulation.  Also, write the BSMs to file. 

\textbf{Program \theprogramcounter{}}
\begin{lstlisting}
int n = obj.numberOfRunsFromSecs(500); /*calculate the number of times runVissimOnce() function should be invoked to run the network for 500 seconds*/
for(int i=0; i<n; i++)
{
    obj.runVissimOnce(); 
    List<BSM> listOfBSM = obj.getBSMforSignalHead("SH1",100); /* listOfBSM contains the list of BSMs of the vehicles of signal head SH1 within 100 meters*/
    obj.displayListOfBSM(listOfBSM); /* displays the BSMs in listOfBSM */
    obj.writeListOfBSMtoFile(listOfBSM); /* writes the BSMs in listOfBSM to file */
}
\end{lstlisting}
\stepcounter{programcounter}

\section{Signal Phasing And Timing Message (SPAT)} \label{SPATmain}
Signal Phasing And Timing Message (SPAT) is a message which gives the information about the phase (state) and the time for which the phase remains, in a signal of an intersection.  Section \ref{SPATfields} explains the fields of SPAT. Section \ref{SPATfunctions} explains the functions or methods for SPAT.

\subsection{SPAT fields} \label{SPATfields}
The java class for SPAT is :
\begin{lstlisting}
public class SPAT
{
    int intersectionId;
    int messageCount;
    String status;  
    ArrayList<spatSignalGroupData> spatSgData;
}
public class spatSignalGroupData
{
    int signalGroupId; 
    String phaseState; 
    float minEndTime; 
}
\end{lstlisting}

The fields of SPAT are explained in Table \ref{table:2}. The field spatSgData contains a list of spatSignalGroupData. The class spatSignalGroupData contains the signal phasing and timing data of a signal group.  The fields of spatSignalGroupData are explained in Table \ref{table:3}.  The field "phaseState" of spatSignalGroupData can be any valid state in VISSIM like \textit{RED, GREEN, AMBER,} and so on.

\begin{table}[h!]
\centering
\begin{tabular}{p{0.15\linewidth}p{0.1\linewidth}p{0.65\linewidth}p{0.1\linewidth}} \hline
Field & Type & Description  & Unit\\ 
\hline
intersectionId & Integer & To identify the intersection & - \\
messageCount & Integer & The number of SPATs sent from the signal group & - \\ 
status & String & The status of the intersection & - \\
spatSgData & ArrayList & Contains the list of phasing and timing data for signal groups & - \\
 & $<$spatSignalGroupData$>$ & & \\
 \hline
\end{tabular}
\caption{SPAT fields}
\label{table:2}
\end{table}

\begin{table}[h!]
\centering
\begin{tabular}{p{0.15\linewidth}p{0.1\linewidth}p{0.65\linewidth}p{0.1\linewidth}} \hline
Field & Type & Description  & Unit\\ 
\hline
signalGroupId & Integer & To identify the signal group of the intersection & - \\
phaseState & String & The phase of the signal group & - \\
minEndTime & float & Conveys the earliest time possible at which the phase could change & Seconds \\
 \hline
\end{tabular}
\caption{spatSignalGroupData fields}
\label{table:3}
\end{table}

\subsection{Functions for SPAT}\label{SPATfunctions}

\subsubsection{public spatSignalGroupData createSPATSignalGroupData(int signalGroupId, String phaseState, float minEndTime)}
This function creates the signal phasing and timing data for a signal group of an intersection. \newline
Parameters: int signalGroupId - Identification number of the signal group, String phaseState - state of signal group, float minEndTime - simulation time in seconds \newline
Return type: spatSignalGroupData - Returns the signal phasing and timing data for a signal group.

\subsubsection{public SPAT createSPAT(int intersectionNumber, String intersecStatus, List$<$spatSignalGroupData$>$ sgData)}
The function creates a SPAT message for a signal group of an intersection (signal controller). \newline
Parameters : int intersectionNumber - Identification number of intersection (signal controller), String intersecStatus - Status of the intersection, List$<$spatSignalGroupData$>$ sgData - List of spatSignalGroupData \newline
Return type : SPAT - Returns the SPAT message created.

\subsubsection{public SPAT createSPAT(String signalControllerName, String intersecStatus, List$<$spatSignalGroupData$>$ sgData)}
The function creates a SPAT message for a signal group of an intersection (signal controller). \newline
Parameters : String signalControllerName - Name of intersection (signal controller), String intersecStatus - Status of the intersection, List$<$spatSignalGroupData$>$ sgData - List of spatSignalGroupData \newline
Return type : SPAT - Returns the SPAT message created.

\subsubsection{public void setSPAT(SPAT s)}
The function sets a specified state for a specified time to the signal groups of the intersection based on the information specified in the SPAT message.  After the specified time, the signal groups are reset to \textit{UNDEFINED} state. \newline
Parameters: SPAT s - s contains a SPAT message \newline
Return type: void 


\subsubsection{public void displaySPAT(SPAT s)}
Displays a SPAT message from a signal group of an intersection. \newline
Parameters: SPAT s - s contains a SPAT message \newline
Return type: void

\subsubsection{public void writeSPAT(SPAT s)}
Writes a SPAT message to the text file specified during object creation of \textit{covettware}. The fields of SPAT are written separated by \textit{,} as follows:\newline
\textit{intersectionNumber, messageCount, intersectionStatus, List of \{signalGroupNumber, minimumEndTime, state\}} \newline
Parameters: SPAT s - s contains a SPAT message \newline
Return type: void

\begin{comment}
\subsubsection{public void displaySignalStatusOfOneIntersection(String signalControllerName)}
Displays signal status of an intersection. \newline
Parameters: String signalControllerName - Name of intersection (signal controller) \newline
Return type: void

\subsubsection{public void displaySignalStatusOfOneIntersection(int intersectionNumber)}
Displays signal status of an intersection. \newline
Parameters: int intersectionNumber - Identification number of intersection (signal controller) \newline
Return type: void

\end{comment}

\subsection{Example} \label{SPATexamples}
\subsubsection{Control signals of an intersection in the network, when intersection number is given}
 Create SPAT message for intersection 1 with status = \verb|FIXED_TIME_OPERATION|, with signal phasing and timing for signal groups as follows. \newline
signalGroupId: 1, State: GREEN, minEndTime: 10 seconds in simulation \newline
 signalGroupId: 2, State: AMBER, minEndTime: 10 seconds in simulation \newline
 signalGroupId: 3, State: REDAMBER, minEndTime: 10 seconds in simulation \newline
 signalGroupId: 4, State: RED, minEndTime: 10 seconds in simulation \newline
 Set the signal groups according to the SPAT message. Display the SPAT message. Also, write the SPAT message to file. 
 
 \textbf{Program \theprogramcounter{}}
 \begin{lstlisting}
spatSignalGroupData d1 = obj.createSPATSignalGroupData(1, "GREEN", 10);
spatSignalGroupData d2 = obj.createSPATSignalGroupData(2,"AMBER", 10);
spatSignalGroupData d3 = obj.createSPATSignalGroupData(3, "REDAMBER", 10);
spatSignalGroupData d4 = obj.createSPATSignalGroupData(4,"RED", 10);
SPAT s = obj.createSPAT(1, "FIXED_TIME_OPERATION", Arrays.asList(d1,d2,d3,d4)); /* SPAT message is created */
obj.setSPAT(s); /* set states of signal groups according to SPAT message */
obj.displaySPAT(s); /* displays SPAT message */
obj.writeSPAT(s); /* writes the SPAT message to file */
\end{lstlisting}
\stepcounter{programcounter}
Sample Output: \newline
intersectionNumber: 1 \newline
messageCount: 1 \newline
intersection status: \verb|FIXED_TIME_OPERATION| \newline
signalGroupNumber: 1, State: GREEN, minEndTime: 10.0 \newline
signalGroupNumber: 2, State: AMBER, minEndTime: 10.0 \newline
signalGroupNumber: 3, State: REDAMBER, minEndTime: 10.0 \newline
signalGroupNumber: 4, State: RED, minEndTime: 10.0 \newline
The content written to file is: \newline
1,1,\verb|FIXED_TIME_OPERATION|,\{1,GREEN,10.0\},\{2,AMBER,10.0\},\{3,REDAMBER,10.0\},\{4,RED,10.0\}



\subsubsection{Control signals of an intersection in the network, when intersection name is given}
 Create SPAT message for intersection "I1" with status = \verb|FIXED_TIME_OPERATION|, with signal phasing and timing for signal groups as follows. \newline
signalGroupId: 1, State: GREEN, minEndTime: 10 seconds in simulation \newline
 signalGroupId: 2, State: AMBER, minEndTime: 10 seconds in simulation \newline
 signalGroupId: 3, State: REDAMBER, minEndTime: 10 seconds in simulation \newline
 signalGroupId: 4, State: RED, minEndTime: 10 seconds in simulation \newline
 Set the signal groups according to the SPAT message. Display the SPAT message. Also, write the SPAT message to file.
 
 \textbf{Program \theprogramcounter{}}
 \begin{lstlisting}
spatSignalGroupData d1 = obj.createSPATSignalGroupData(1, "GREEN", 10);
spatSignalGroupData d2 = obj.createSPATSignalGroupData(2,"AMBER", 10);
spatSignalGroupData d3 = obj.createSPATSignalGroupData(3, "REDAMBER", 10);
spatSignalGroupData d4 = obj.createSPATSignalGroupData(4,"RED", 10);
SPAT s = obj.createSPAT("I1", "FIXED_TIME_OPERATION", Arrays.asList(d1,d2,d3,d4)); /* SPAT message is created */
obj.setSPAT(s); /* set states of signal groups according to SPAT message */
obj.displaySPAT(s); /* displays SPAT message */
obj.writeSPAT(s); /* writes the SPAT message to file */
\end{lstlisting}
\stepcounter{programcounter}

    
\section{Testing of connected vehicle traffic control algorithm} \label{messageGeneration}
The steps to be followed to test any connected vehicle traffic control algorithm is as follows.
\begin{itemize}
    \item Add \textit{jacob.jar} and \textit{covettwareProject.jar} to the library of your project
    \item Create an object of \textit{covettware} using the function in Section \ref{objectCreation}
    \item Generate BSMs using functions of Section \ref{BSMmain}
    \item Use the BSMs in the connected vehicle traffic control algorithm  to generate signal status data
    \item Generate the SPAT messages using functions in Section \ref{SPATmain}.
    \item Invoke the function \textit{finalStep} expalined in Section \ref{finalStep}
\end{itemize}




 \subsection{An example of fixed-time signal generation algorithm}
 Let \textit{testInputGeneration.inpx} be the VISSIM input file. Let \textit{BSM.txt} and \textit{SPAT.txt} be the files to which BSM and SPAT messages are to be written. Assume VISSIM input consists of 5 intersections with four signal groups 1, 2, 3, and 4. Create a fixed-time signal generator where the signal status changes every 20 seconds in the simulation. The signal states should be \verb|GREEN|, \verb|AMBER|, \verb|REDAMBER|, and \verb|RED|. The simulation should run for 5000 seconds in simulation. Display the SPAT messages and also write to file.
 
\textbf{Program \theprogramcounter{}}
\begin{lstlisting}
public class ConnectedVehicles 
{
    public static void main(String[] args) 
    {
        covettware obj = new covettware("testInputGeneration.inpx", "BSM.txt","SPAT.txt"); /* creates an object of covettware */
        int n = obj.numberOfRunsFromSecs(5000); /*calculate the number of times runVissimOnce() function should be invoked to run the network for 5000 seconds*/
        int x = obj.numberOfRunsFromSecs(20); /*calculate the number of times runVissimOnce() function should be invoked to run the network for 20 seconds*/
        SPAT s;
        int sgGreen = 0, sgAmber = 1, sgRedAmber = 2, sgRed = 3; 
        for(int i=0; i<n; i++)
        {
            obj.runVissimOnce();
            if(i%x==0) /* condition is true every 20 simulation seconds */
            {
                for(int inters = 1; inters<=5; inters++) /* loops each intersection */
                {
                    spatSignalGroupData d1 = obj.createSPATSignalGroupData(sgGreen+1, "GREEN", 20);
                    spatSignalGroupData d2 = obj.createSPATSignalGroupData(sgAmber+1,"AMBER", 20);
                    spatSignalGroupData d3 = obj.createSPATSignalGroupData(sgRedAmber+1, "REDAMBER", 20);
                    spatSignalGroupData d4 = obj.createSPATSignalGroupData(sgRed+1,"RED", 20);
                    s = obj.createSPAT(inters, "FIXED_TIME_OPERATION", Arrays.asList(d1,d2,d3,d4)); /* SPAT object created*/
                    obj.setSPAT(s); /* set states of signal groups */
                    obj.displaySPAT(s); /* displays SPAT */
                    obj.writeSPAT(s); /* writes SPAT to file */
                }
                sgGreen = (sgGreen + 1)%4;
                sgAmber = (sgAmber + 1)%4;
                sgRedAmber = (sgRedAmber + 1)%4;
                sgRed = (sgRed + 1)%4;
            }
        }
        obj.finalStep(); /* safe closing of VISSIM and files */
    }
}
\end{lstlisting}

\end{document}